package com.xxx.shetuan3.controller;

import com.xxx.shetuan3.common.CommonResult;
import com.xxx.shetuan3.pojo.StudentAndOrganization;
import com.xxx.shetuan3.service.StudentAndOrganizationService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/student-organization")
public class StudentAndOrganizationController {
    @Autowired
    private StudentAndOrganizationService studentAndOrganizationService;
    @ApiOperation("添加一个学生社团关系")
    @PostMapping("/")
    public CommonResult saveStudentAndOrganization(StudentAndOrganization studentAndOrganization){
        studentAndOrganizationService.saveStudentAndOrganization(studentAndOrganization);
        return CommonResult.success();
    }

    @ApiOperation("更新学生社团关系状态")
    @PostMapping("/{studentAndOrganizationId}")
    public CommonResult updateStudentAndOrganizationStateByStudentAndOrganizationId(
            @PathVariable(value = "studentAndOrganizationId") Integer studentAndOrganizationId,
            String state){
        studentAndOrganizationService.updateStudentAndOrganizationStateByStudentAndOrganizationId(state,studentAndOrganizationId);
        return CommonResult.success();
    }

    @ApiOperation("删除学生社团关系")
    @DeleteMapping("/{studentAndOrganizationId}}")
    public CommonResult deleteStudentAndOrganizationById(
            @PathVariable(value = "studentAndOrganizationId") Integer studentAndOrganizationId){
        studentAndOrganizationService.deleteStudentAndOrganizationById(studentAndOrganizationId);
        return CommonResult.success();
    }

    @ApiOperation("根据社团号查询申请的成员")
    @GetMapping("/find-apply")
    public CommonResult<List<StudentAndOrganization>> findUnacceptedStudent(Integer organizationId,
                                                                   @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                                   @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<StudentAndOrganization> res = studentAndOrganizationService.findUnacceptedStudent(organizationId, start, size);
        return CommonResult.success(res);
    }


    @ApiOperation("根据社团id查询所有加入的所有学生")
    @GetMapping("/findstu")
    public CommonResult<List<StudentAndOrganization>> findStudents(Integer organizationId,
                                                                   @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                                   @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<StudentAndOrganization> res = studentAndOrganizationService.findStudents(organizationId, start, size);
        return CommonResult.success(res);
    }

    @ApiOperation("根据学生id查询所有该学生的社团申请信息")
    @GetMapping("/find-apply1")
    public CommonResult<List<StudentAndOrganization>> findUnacceptedOrganizations(Integer studentId,
                                                                   @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                                   @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<StudentAndOrganization> res = studentAndOrganizationService.findUnacceptedOrganizations(studentId, start, size);
        return CommonResult.success(res);
    }

    @ApiOperation("根据学生id查询该学生加入的所有社团")
    @GetMapping("/find-apply2")
    public CommonResult<List<StudentAndOrganization>> findOrganizations(Integer studentId,
                                                                   @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                                   @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<StudentAndOrganization> res = studentAndOrganizationService.findOrganizations(studentId, start, size);
        return CommonResult.success(res);
    }
}
